import { createStore } from 'vuex'
import createPersistedstate from 'vuex-persistedstate'

// 直接引入所有的模块
const modulesFiles = import.meta.globEager('./modules/**/*.js')

const modules = {}
for (const key in modulesFiles) {
  modules[key.replace(/(\.\/modules\/|\.js)/g, '')] = modulesFiles[key].default
}

Object.keys(modules).forEach(item => {
  modules[item]['namespaced'] = true
})

const store = createStore({
  plugins: [createPersistedstate({ key: 'saveInfo', paths: ['user'] })],
  getters: {},
  modules
})

export default store
